package com.movie.demo.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movie.demo.mapper.CinemaMapper;
import com.movie.demo.pojo.Cinema;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
@Service
public class CinemaService extends ServiceImpl<CinemaMapper, Cinema> implements com.movie.demo.service.CinemaService {
    @Override
    public List<Cinema> selectCinema() {
       List<Cinema> cinemaList=this.selectList(new EntityWrapper<Cinema>());
        return cinemaList;
    }

    @Override
    public Boolean addCinema(Cinema cinema) {
        Cinema cinemas = this.selectOne(new EntityWrapper<Cinema>().eq("cname", cinema.getCname()).or
                ().eq("phone",cinema.getPhone()));
        if (Objects.isNull(cinemas)||cinemas==null){
            this.insert(cinema);
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteCinema(Integer cid) {
        boolean flag = this.deleteById(cid);
        return flag;
    }

    @Override
    public boolean updateCinema(Cinema cinema) {
        boolean flag = this.updateById(cinema);
        return flag;
    }
}
